package com.example.jpa.springbootjpa.controller;

import com.example.jpa.springbootjpa.domian.Cat;
import com.example.jpa.springbootjpa.service.CatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author kalista
 * @version 1.0.0
 */
@RestController
@RequestMapping("/")
public class CatController {

    @Autowired
    private CatService catService;

    @GetMapping("/save")
    public String save(){
        Cat cat = new Cat();
        cat.setCatName("jack");
        cat.setCatAge("3");
        catService.save(cat);
        return "save ok.";
    }
    @GetMapping("/delete")
    public String delete(){
        catService.delete(1);
        return "delete ok";
    }
    @GetMapping("/getAll")
    public Iterable<Cat> getAll(){
        return catService.getAll();
    }

    @GetMapping("/get")
    public Cat getCatName(String catName){
        return catService.query(catName);
    }
}
